package com.chinasoft.carservice.mapper;

import com.chinasoft.ms.pojo.Car;
import com.chinasoft.ms.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CarMpper {

    @Select("select * from car ")
    List<Car> selectAll();

    @Select("<script>" +
            "SELECT * FROM car " +
            "<where>" +
            "   <if test='model != null'>AND model LIKE CONCAT('%', #{model}, '%')</if>" +
            "   <if test='licensePlate != null'>AND license_plate LIKE CONCAT('%', #{licensePlate}, '%')</if>" +
            "   <if test='manufacturer != null'>AND manufacturer LIKE CONCAT('%', #{manufacturer}, '%')</if>" +
            "</where>" +
            "</script>")
    List<Car> selectByCondition(Car car);


    @Insert("insert into car(license_plate, model, price_per_day, manufacturer, production_year, status, rental_count) " +
            "values(#{licensePlate}, #{model}, #{pricePerDay}, #{manufacturer}, #{productionYear}, #{status}, #{rentalCount})")
    void insert(Car car);

    @Update("update car set license_plate = #{licensePlate}, model = #{model}, price_per_day = #{pricePerDay}, " +
            "manufacturer = #{manufacturer}, production_year = #{productionYear} "+
            "where id = #{id}"
    )
    void updateById(Car car);

    @Update("update car set status =#{status} "+
            "where id = #{id}"
    )
    void updateByIds(Car car);
    @Delete("delete from car where id = #{id}")
    void deleteById(Long id);

    @Select("select * from car where id = #{id}")
    Car selectById(Long id);

    @Update("UPDATE car SET status = #{s} WHERE id = #{carId}")
    boolean updateStatus(Long carId, String s);
}
